<template>
	<view class="voucher">
		<view class="main1">
			<view class="title">
				<view class="top">
					<view class="view1">{{couponInfo.storeName}}</view>
					<view class="view2">{{couponInfo.name}}</view>
				</view>
				<view class="scroll-item-bottom">
					<view class="item-bottom_left"></view>
					<view class="item-bottom_center">
						<view class="center-xian"></view>	
					</view>
					<view class="item-bottom_right"></view>
				</view>	
				<view class="bottom">
					{{couponInfo.useTime}}
				</view>
			</view>
			<view class="center">
				<view class="left">
					<view class="view1">￥{{couponInfo.price/100}}</view>
					<view class="view2">{{couponInfo.discount}} 折</view>
					<view class="view3">原价￥{{couponInfo.faceValue/100}} </view>
				</view>
				<view class="right">已售 {{couponInfo.saleNum}}</view>
			</view>
			<view class="content">
				<view class="item">
					<view class="left">可用时间</view>
					<view class="right">{{couponInfo.useTime}}</view>
				</view>
				<view class="item">
					<view class="left">使用数量</view>
					<view class="right" v-if="couponInfo.useNum==0">不限制</view>
					<view class="right" v-else>
						限使用{{couponInfo.useNum}}张
					</view>
				</view>
				<view class="item">
					<view class="left">适用范围</view>
					<view class="right">{{couponInfo.useScope}}</view>
				</view>
				<view class="item">
					<view class="left">服务保障</view>
					<view class="right">随时退·过期自动退</view>
				</view>
				
			</view>
		</view>
	  <view class="main2">
			<view class="title">
				使用规则
			</view>
			<view class="content">
				<view class="item">
					<view class="left"></view>
					<view class="right">{{couponInfo.rules}}</view>
				</view>
			</view>
		</view>
		<view class="main3">
			<view class="title">
				商品详情
			</view>
			<view class="content">
				<view class="item">
					<image class="img" :src="item" mode="aspectFit" v-for="(item,index) in couponInfo.imgs"></image>
				</view>
			</view>
		</view>
	
	  <view class="foot">
			<view class="foot_box">
				<view class="pir">
				<view class="left" @click="WeixinServer">
					<image src="../../static/service.png" mode="aspectFill" class="img"></image>
					<view>联系客服</view>
				</view>	
				<view class="right">
					<view class="btn" @click="buyCoupon">立即抢购</view>
					<button v-if="!mineInfo.phone && mineInfo.phone.length!==11" open-type="getPhoneNumber" @getphonenumber.stop="onGetPhoneNumber"></button>
				</view>	
				
				</view>
			</view>	
		</view>
	</view>
</template>

<script>
	import { storeCoupon } from '../../apis/invite.js';
	import http from '@/utils/request/http.js';
	var app = getApp();	
	import gongType from '@/utils/debounce.js'
	export default {
		data() {
			return {
				arr:[{},{},{}],
				id:'',//代金券id
				couponInfo:{},
				mineInfo:{},
			}
		},
		onLoad(options) {
			let that = this;
			app.isLogin({},function(login){
				console.log(login,"loginlogin")
				that.mineInfo = login;
			})
				
				
			console.log(options,"代金券id")
			that.id = options.id;
			this.getStoreCoupon();
		},
		
		onShow(){
			
		},
		methods: {
			// 手机号授权
			onGetPhoneNumber(e){
				let that = this;
				app.GetMobile(e,function(e){
					// that.phoneLoginFlag = true;
					if(that.inviteId !==''){
						app.isLogin({id:that.inviteId},function(login){
							that.mineInfo = login;
						});
					}else {
						app.getUserInfo(function(lRes){
							that.mineInfo = lRes;
						})
					}
				});
			},
			//  获取代金券详情
			getStoreCoupon(){
				let that = this;
				storeCoupon({
					id:that.id
				}).then( res => {
					switch(res.code){
						case 200:
							console.log(res,"res")
							this.couponInfo=res.data
						break;
						default:
							uni.showToast({
								title:res.message,
								icon:"none"
							})
						break;
					}
				})
			},
			buyCoupon:gongType.debounce(function (e){
				let that = this;
				let parms = {
					id :that.id,
				}
				http.post('/api/order/v1/coupon/buy',parms).then( payment => {
					console.log(payment,"订单接口1")
					switch(payment.code){
						case 200:
							app.WxPayMent(payment.data).then( res => {
								console.log(res,"订单接口2")
								app.getUserInfo(function(lRes){
									that.mineInfo = lRes;
									// uni.navigateBack({
									// 	delta:1
									// })
									uni.navigateTo({
										url: `/pageB/voucherCode/voucherCode?orderId=${payment.data.id}`
									})
								})
							})
						break;
						default:
							uni.showToast({
								title:payment.message,
								icon:'none'
							})
						break;
					}
				});
			
			}, 1000),
			// 接入微信客服
			WeixinServer(){
				console.log("打开客服")
				wx.openCustomerServiceChat({
					extInfo: {
						url: 'https://work.weixin.qq.com/kf/' + "kfc11f5184d7762c658"
					},
					 corpId: 'ww106853c8ad050781',
				})
			},
		}
	}
</script>
<style>
	page {
		background: #F4F6FA;
	}
</style>
<style lang="scss" sc>
.voucher{
	width: 100%;
	padding-bottom: 200rpx;
	.main1{
		width: 650rpx;
		border-radius: 32rpx;
		background: #fff;
		padding: 30rpx;
		margin: 20rpx auto;
		.title{
			width: 100%;
			min-height: 220rpx;
			// height: 220rpx;
			background: #FFF5F1;
			border-radius: 32rpx;
			.top{
				padding: 30rpx 24rpx 0rpx;
				.view1{
					font-weight: 400;
					font-size: 24rpx;
					color: #666666;
				}
				.view2{
					font-weight: 500;
					font-size: 36rpx;
					color: #141414;
					margin-top: 4rpx;
				}
			}
			.scroll-item-bottom{
				display: flex;
				position: relative;
				width: 100%;
				align-items: center;
				.item-bottom_left{
					width: 20rpx;
					height: 40rpx;
					background-color: #fff;
					border-radius: 0 40rpx 40rpx 0;
					position: absolute;
					left: 0;
				}
				.item-bottom_center{
					width: 100%;
					margin: 30rpx 0 20rpx;
					.center-xian{
						width: 610rpx;
						border-top: 1px dashed rgba(244, 59, 0, 0.3);
						margin: auto;
					}
				}
				.item-bottom_right{
					width: 20rpx;
					height: 40rpx;
					background-color: #fff;
					border-radius: 0 40rpx 40rpx 0;
					position: absolute;
					right: 0;
					transform: rotate(180deg);
				}
			}
			.bottom{
				font-size: 24rpx;
				color: #666666;
				padding: 0rpx 24rpx 20rpx;
			}
		}
		.center{
			display: flex;
			align-items: center;
			border-bottom: 1rpx solid #EFEFEF;
			padding: 30rpx 0;
			.left{
				display: flex;
				align-items: center;
				flex: 1;
				.view1{
					font-weight: 700;
					font-size: 32rpx;
					color: #F43B00;
				}
				.view2{
					color: #F43B00;
					font-weight: 400;
					font-size: 18rpx;
					border: 1rpx solid #F43B00;
					border-radius: 16rpx;
					padding: 0 8rpx;
					margin-left: 10rpx;
				}
				.view3{
					font-weight: 400;
					font-size: 18rpx;
					color: #999999;
					margin-left: 10rpx;
				}
			}
			.right{
				font-weight: 400;
				font-size: 20rpx;
				color: #999999;
			}
		}
		.content{
			padding: 30rpx 0 0rpx;
			.item{
				display: flex;
				align-items: center;
				margin-bottom: 20rpx;
				.left{
					font-weight: 400;
					font-size: 20rpx;
					color: #999999;
				}
				.right{
					font-weight: 400;
					font-size: 20rpx;
					color: #333333;
					padding-left: 20rpx;
				}
			}
		}
	}
	.main2{
		width: 650rpx;
		border-radius: 32rpx;
		background: #fff;
		padding: 30rpx;
		margin: 20rpx auto;
		.title{
			font-weight: 700;
			font-size: 32rpx;
			color: #333333;
			padding: 0 0 30rpx;
		}
		.content{
			.item{
				display: flex;
				align-items: center;
				margin-bottom: 20rpx;
				.left{
					width: 6rpx;
					height: 6rpx;
					border-radius: 50%;
					background: #666;
				}
				.right{
					font-weight: 400;
					font-size: 24rpx;
					color: #666666;
					padding-left: 12rpx;
				}
			}
		}
	}
	.main3{
		width: 650rpx;
		border-radius: 32rpx;
		background: #fff;
		padding: 30rpx;
		margin: 20rpx auto;
		.title{
			font-weight: 700;
			font-size: 32rpx;
			color: #333333;
			padding: 0 0 30rpx;
		}
		.content{
			.item{
				display: flex;
				align-items: center;
				flex-direction: column;
				margin-bottom: 20rpx;
				.img{
					width: 100%;
				}
			}
		}
	}
	.foot{
		height: 120rpx;
		width: 100%;
		position: fixed;
		bottom: 40rpx;
		z-index: 99;
		.foot_box{
			margin: 0 20rpx;
			height: 120rpx;
			// background: #fff;
			box-shadow: 0px 0px 20px rgba(162, 39, 0, 0.4);
			border-radius: 64rpx;
			display: flex;
			align-items: center;
			.pir{
				width: 100%;
				    height: 100%;
				    display: flex;
				    align-items: center;
			}
			.left{
				// width: 260rpx;
				height: 100%;
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;
				background: #fff;
				border-radius: 64rpx 0 0 64rpx;
				width: 35%;
				.img{
					width: 48rpx;
					height: 48rpx;
				}
				view{
					font-weight: 400;
					font-size: 20rpx;
					color: #666666;
					margin-top: 6rpx;
				}
			}
			.right{
				width: 65%;
				// width: 450rpx;
				height: 100%;
				background: #F43B00;
				color: #FFFFFF;
				font-weight: 700;
				font-size: 32rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				border-radius: 0 64rpx 64rpx 0;
				position: relative;
				.btn{
					width: 100%;
					height: 100%;
					display: flex;
					align-items: center;
					justify-content: center;
				}
				button{
					    width: 100%;
					    height: 100%;
					    position: absolute;
					    top: 0;
					    left: 0;
					    opacity: 0;
				}
			}
		}
	}
}
</style>
